<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        <f:view beforePhase="#{viewSaleLeadsInquiries.initView}">
            <p:panel id="panel" header="View Sale Lead's Sale Inquiries">
                <h:form prependId="false">
                    <p:dataTable id ="table1" var="saleInquiry" value="#{viewSaleLeadsInquiries.selectedSaleInquiries}" 
                                 selection ="#{viewSaleLeadsInquiries.selectedSaleInquiry}" onRowSelectUpdate="display"
                                 dynamic="true" paginator="true" rows="5" emptyMessage="No Sale Inquiries" > 

                        <p:column selectionMode="single" />
                        <p:column sortBy="#{saleInquiry.id}" filterBy="#{saleInquiry.id}"> 
                                    <f:facet name="header"> 
                                        <h:outputText value="Sale Inquiry ID" /> 
                                    </f:facet> 
                                    <h:outputText value="#{saleInquiry.id}" /> 
                        </p:column> 

                        <p:column sortBy="#{saleInquiry.saleInquiryDate}" filterBy="#{saleInquiry.saleInquiryDate}"> 
                            <f:facet name="header"> 
                                <h:outputText value="Date" /> 
                            </f:facet> 
                            <h:outputText value="#{saleInquiry.saleInquiryDate}" /> 
                        </p:column> 

                        <p:column sortBy="#{saleInquiry.saleLead.registrationNumber}"> 
                            <f:facet name="header"> 
                                <h:outputText value="Registration Number" /> 
                            </f:facet> 
                            <h:outputText value="#{saleInquiry.saleLead.registrationNumber}" /> 
                        </p:column>

                        <p:column sortBy="#{saleInquiry.saleLead.saleLeadName}"> 
                            <f:facet name="header"> 
                                <h:outputText value="Sale Lead Name" /> 
                            </f:facet> 
                            <h:outputText value="#{saleInquiry.saleLead.saleLeadName}" /> 
                        </p:column>
                        
                        <f:facet name="footer">  
                            <p:commandButton value="View" image="ui-icon ui-icon-search" update="display1 display2" oncomplete="inquiryViewDialog.show()"/>
                            <p:commandButton value="Edit" image="ui-icon ui-icon-pencil" actionListener="#{viewSaleLeadsInquiries.editSaleInquiry}">
                                <f:attribute name="selectedSaleInquiry" value="#{selectedSaleInquiry}"/>
                            </p:commandButton>  

                            <p:commandButton value="Delete" image="ui-icon ui-icon-trash" update="display3 display4" oncomplete="inquiryDeleteDialog.show()"/>
                            <p:commandButton value="Convert to Sale Quotation" image="ui-icon ui-icon-arrowreturnthick-1-e" actionListener="#{viewSaleLeadsInquiries.convertToSaleQuotation}">
                                <f:attribute name="selectedSaleInquiry" value="#{selectedSaleInquiry}"/>
                            </p:commandButton>                                
                        </f:facet>
                        
                    </p:dataTable>
                    
                    <p:dialog header="Sale Inquiry Detail" widgetVar="inquiryViewDialog" width="700" height="400" resizable="true" showEffect="fold" hideEffect="fold">
                    <h:panelGrid id="display1" columns="2" cellpadding="5">

                        <h:outputText value="Sale Inquiry ID:"/>
                        <h:outputText value="#{viewSaleLeadsInquiries.selectedSaleInquiry.id}"/>

                        <h:outputText value="Date:"/>
                        <h:outputText value="#{viewSaleLeadsInquiries.selectedSaleInquiry.saleInquiryDate}"/>

                        <h:outputText value="Company Name:"/>
                        <h:outputText value="#{viewSaleLeadsInquiries.selectedSaleInquiry.saleLead.saleLeadName}"/>

                        <h:outputText value="Registration Number:"/>
                        <h:outputText value="#{viewSaleLeadsInquiries.selectedSaleInquiry.saleLead.registrationNumber}"/>

                        <h:outputText value="Custom Discount(%):"/>
                        <h:outputText value="#{viewSaleLeadsInquiries.selectedSaleInquiry.customDiscount}"/>

                    </h:panelGrid>

                    <p:dataTable var="lineItem" value="#{viewSaleLeadsInquiries.selectedSaleInquiry.lineItems}"
                                 dynamic="true" paginator="true" emptyMessage="No Product Type" id="display2">
                        <p:column sortBy="#{lineItem.product.productType}">
                            <f:facet name="header">
                                <h:outputText value="Type"/>
                            </f:facet>
                            <h:outputText value="#{lineItem.product.productType}"/>
                        </p:column>

                        <p:column sortBy="#{lineItem.lineItemQuantity}">
                            <f:facet name="header">
                                <h:outputText value="Quantity"/>
                            </f:facet>
                            <h:outputText value="#{lineItem.lineItemQuantity}"/>
                        </p:column>

                        <p:column sortBy="#{lineItem.product.productPrice}">
                            <f:facet name="header">
                                <h:outputText value="Price per Unit($)"/>
                            </f:facet>
                            <h:outputText value="#{lineItem.product.productPrice}"/>
                        </p:column>

                        <p:column sortBy="#{lineItem.volumeDiscountRate}">
                            <f:facet name="header">
                                <h:outputText value="Volume Discount(%)"/>
                            </f:facet>
                            <h:outputText value="#{lineItem.volumeDiscountRate}"/>
                        </p:column>

                        <p:column sortBy="#{lineItem.finalPrice}">
                            <f:facet name="header">
                                <h:outputText value="Final Price($)"/>
                            </f:facet>
                            <h:outputText value="#{lineItem.finalPrice}"/>
                        </p:column>

                        <f:facet name="footer">
                            <h:outputText value ="Total Price: "/>
                            <h:outputText value ="#{viewSaleLeadsInquiries.selectedSaleInquiry.totalPrice}"/>
                        </f:facet>
                     </p:dataTable>
           </p:dialog>
                    
                    <p:dialog header="Sale Inquiry Detail" widgetVar="inquiryDeleteDialog" width="700" height="400" resizable="false" showEffect="explode" hideEffect="explode">
                    <h:panelGrid id="display3" columns="2" cellpadding="5">

                        <h:outputText value="Sale Inquiry ID:"/>
                        <h:outputText value="#{viewSaleLeadsInquiries.selectedSaleInquiry.id}"/>

                        <h:outputText value="Date:"/>
                        <h:outputText value="#{viewSaleLeadsInquiries.selectedSaleInquiry.saleInquiryDate}"/>

                        <h:outputText value="Company Name:"/>
                        <h:outputText value="#{viewSaleLeadsInquiries.selectedSaleInquiry.saleLead.saleLeadName}"/>

                        <h:outputText value="Registration Number:"/>
                        <h:outputText value="#{viewSaleLeadsInquiries.selectedSaleInquiry.saleLead.registrationNumber}"/>

                        <h:outputText value="Custom Discount(%):"/>
                        <h:outputText value="#{viewSaleLeadsInquiries.selectedSaleInquiry.customDiscount}"/>

                    </h:panelGrid>

                    <p:dataTable var="lineItem" value="#{viewSaleLeadsInquiries.selectedSaleInquiry.lineItems}"
                                 dynamic="true" paginator="true" emptyMessage="No Product Type" id="display4">
                            <p:column sortBy="#{lineItem.product.productType}">
                                <f:facet name="header">
                                    <h:outputText value="Type"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.product.productType}"/>
                            </p:column>

                            <p:column sortBy="#{lineItem.lineItemQuantity}">
                                <f:facet name="header">
                                    <h:outputText value="Quantity"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.lineItemQuantity}"/>
                            </p:column>

                            <p:column sortBy="#{lineItem.product.productPrice}">
                                <f:facet name="header">
                                    <h:outputText value="Price per Unit($)"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.product.productPrice}"/>
                            </p:column>

                        <p:column sortBy="#{lineItem.volumeDiscountRate}">
                            <f:facet name="header">
                                <h:outputText value="Volume Discount(%)"/>
                            </f:facet>
                            <h:outputText value="#{lineItem.volumeDiscountRate}"/>
                        </p:column>

                        <p:column sortBy="#{lineItem.finalPrice}">
                            <f:facet name="header">
                                <h:outputText value="Price($)"/>
                            </f:facet>
                            <h:outputText value="#{lineItem.finalPrice}"/>
                        </p:column>   

                        <f:facet name="footer">
                            <h:outputText value ="Total Price: "/>
                            <h:outputText value ="#{viewSaleLeadsInquiries.selectedSaleInquiry.totalPrice}"/>
                        </f:facet>

                     </p:dataTable>

                    <p:spacer height="35"/>

                     <p:commandButton value="Confirm Delete" image="ui-icon ui-icon-trash" actionListener="#{viewSaleLeadsInquiries.deleteSaleInquiry}" oncomplete="inquiryDeleteDialog.hide()">
                            <f:attribute name="selectedSaleInquiry" value="#{saleInquiry}"/>
                     </p:commandButton>
                    <p:commandButton value="Cancel" image="ui-icon ui-icon-close" onclick="inquiryDeleteDialog.hide()"/>
                    <p:messages />

                </p:dialog>


                </h:form>
            </p:panel>
        </f:view>
    </ui:define>
</ui:composition>
